package com.enjoy.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public String get(String productCacheKey) {
        return stringRedisTemplate.opsForValue().get(productCacheKey);
    }

    public void set(String productCacheKey, String value, long timeout, TimeUnit timeUnit) {
        stringRedisTemplate.opsForValue().set(productCacheKey, value, timeout, timeUnit);
    }

    public void set(String productCacheKey, String value) {
        stringRedisTemplate.opsForValue().set(productCacheKey, value);
    }

    public void expire(String productCacheKey, long timeout, TimeUnit timeUnit) {
        stringRedisTemplate.expire(productCacheKey, timeout, timeUnit);
    }
}
